﻿namespace MusicDiary.Lib.Models;

public class PlaylistModel
{
    public string? Image { get; set; }
    public int Key { get; set; }
    public PlaylistModel(string path)
    {
        if (!Directory.Exists(path)) Name = "";
        var dir = new DirectoryInfo(path);
        Name = dir.Name;
        Musics = dir.GetFiles()
            .Where(x => x.Extension is ".mp3" or ".flac")
            .Select(x => new MusicModel(x.FullName)).ToList();
        if (Musics.Count > 0)
            Image ??= Musics[0].Url;
    }

    public PlaylistModel() => Key = 0;

    public string Name { get; set; } = "";
    public List<MusicModel> Musics { get; set; } = new ();
}